class MainController < ApplicationController
  
  layout "main"
  def index
    @advertisments   = Advertisment.paginate:page => params[:page],:per_page => 4,:conditions =>"user_id!=''",:order => 'created_at DESC'
    #@all_categories = UserType.find_by_stripped_name("student").categories
    @user_categories = $userwise_categories["student"]["Categories"]
    @all_categories  = Category.find_by_sql("select * from categories where " + @user_categories)
    #@user_types = UserType.find(:all, :include => [:categories],:conditions=>"stripped_name!='"+params[:user_profile].gsub("-","")+"'")
    #@all_categories =
    get_university
  end


  def get_university
    @filter=""
    unless (params[:filter]).nil? || params[:filter]==""
      @filter="stripped-name like'%"+params[:filter]+"%'"
    end

    if(params[:check]=="alpha")
      @universities =  University.find(:all, :order=>"name", :include => :city,:conditions=>@filter)
      @val = "alpha"
    
    else
      @val="cities"
    end
    @cities = City.find(:all , :order =>"name",:conditions=>@filter)
  end

  def view_university
      get_university
      render :partial => "main/view_university"
  end
  def forcategory_view_university
      get_university
      render :partial => false

      
  end

  def auto_university
      @universities = University.find_by_sql("Select * from cities c inner join universities u on c.id=u.city_id where c.name like '%"+params["university_query"].capitalize+ "%' or u.name like '%"+params["university_query"].capitalize+ "%' order by u.name")
      @val="alpha"
      render :partial => "main/view_university"
  end
  

end
